<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ko" lang="ko">
<head>
    <title>Javascript 二维码生成库：QRCode</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
    <meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=no"/>
    <!--<script type="text/javascript" src="./js/jquery.min.js"></script>-->
    <!--<script type="text/javascript" src="./js/qrcode.min.js"></script>-->
    <script type="text/javascript" src="http://static.runoob.com/assets/jquery/2.0.3/jquery.min.js"></script>
    <script type="text/javascript" src="http://static.runoob.com/assets/qrcode/qrcode.min.js"></script>
    <script src="../plugins/healthmobile.js"></script>
    <script src="../plugins/vue/axios-0.18.0.js"></script>
</head>
<script>
    var id = getUrlParam("id");//  获取浏览器请求对应参数
</script>
<body>
<input id="text" type="text" value= "url" style="width:80%"/><br/>
<div id="qrcode" style="width:100px; height:100px; margin-top:15px;"></div>

<div id="timer" style="color:red"></div>

<div><img src="../img/支付.jpg" alt=""/></div>
<script type="text/javascript">
    var qrcode = new QRCode(document.getElementById("qrcode"), {
        width: 100,
        height: 100
    });

    function makeCode() {
        var elText = document.getElementById("text");
        axios.get("/payer/"+id).then(res=>{
           let url =res.data;
           elText.value=url;
           qrcode.makeCode(url);
        })
    }
    makeCode();

    $("#text").on("blur", function () {
        makeCode();
    }).on("keydown", function (e) {
        if (e.keyCode == 13) {
            makeCode();
        }
    });


    // 每间隔五秒查询支付状态

    setInterval(
        function makeCode() {
            axios.get("/selStatus/"+id).then(res=>{
                if (res.data.data==2){
                    location.href='pay_success.html';
                }
            })
        }
    ,1500);

    setTimeout(function () {
        location.href='pay_fail.html';
    },30000);



    var oBox= document.getElementById('timer');
    var maxtime = 29;
    function CountDown() {
        if (maxtime >= 0) {
            minutes = Math.floor(maxtime / 60);
            seconds = Math.floor(maxtime % 60);
            msg = "距离结束还有" + minutes + "分" + seconds + "秒";
            oBox.innerHTML = msg;
            if (maxtime == 5 * 60)alert("还剩5分钟");
            --maxtime;
        } else{
            clearInterval(timer);
            alert("时间到，结束!");
        }
    }
    timer = setInterval("CountDown()", 1000);

</script>
</body>
</html>